<?php namespace Common\Model;
use Hdphp\Model\Model;
class GoodsList extends Model{
	
	protected $table = "360mall_gliist";
    protected $validate = array(
       array("gl_combine","required","货品属性不能为空",3,3),
	    array("gl_inventory","num:0,4000000","库存必须位数字",3,3),
	);	
	
	
	//添加
	public function store(){
		if(!$this->create()) return false;
		$data = implode(",", $_POST['gl_combine']);
		$_POST['gl_combine']=$data;
	   //判断货品是否存在
		$olddata = $this->where("gl_combine","$data")->get();
		if(!empty($olddata)){
			$this->error = "货品已存在";
			return false;
		}
		$this->add($_POST);
		return true;
	}
	public function edit($glid){

		if(!$this->create()) return false;
		$_POST['gl_combine'] = implode(",", $_POST['gl_combine']);
		$olddata = $this->where("gl_combine",$_POST['gl_combine'])-> WhereNotIn("gl_id",array('gl_id'=>$glid))->get();
       if(!empty($olddata)){
			$this->error = "货品已存在";
			return false;
		}
		$this->save($_POST);
		return true;
	}
}